import puppeteer from "../../../lib/puppeteer/puppeteer.js";
import {
    PLUGIN_PATH,
    readConfiguration
} from '../function/function.js';

export class Bs extends plugin {
    constructor() {
        super({
            name: '[Bs]菜单',
            dsc: '菜单',
            event: 'message',
            priority: 1,
            rule: [
                { reg: /^[#\/]?(面包(商店)?|Bs)(菜单|帮助)/i, fnc: 'help' }
            ]
        })
    }

    async help(e) {
        /** 配置数据 */
        const configData = await readConfiguration()
        /** 默认物品 */
        let defaultItem = configData['bread_thing']
        /** 自定义物品 */
        const CUSTOM_ITEMS = configData['special_thing_group'][e.group_id]

        // 存在自定义物品 默认物品修改为自定义物品
        if (CUSTOM_ITEMS) {
            defaultItem = CUSTOM_ITEMS
        }

        /** 帮助图片 */
        const image = await puppeteer.screenshot('面包帮助', {
            tplFile: 'plugins/Bread-Shop/resources/html/help/index.html',
            filePath: `${PLUGIN_PATH}/resources/`,
            defaultItem
        })

        return e.reply([image])
    }
}